package com.work.mybatis.mapper;

import com.work.mybatis.annotations.User;

import java.util.List;
//方法接口类
public interface UserMapper {
   //select为对应的注释语句

    //按照名字和年龄查找
    @Select("SELECT * FROM `user` WHERE name = #{name} and age = #{age}")
    public List<User> getUserNameAndAge(@Param("name") String name, @Param("age") Integer age);
    //按照名字查找
    @Select("SELECT * FROM `user` WHERE name = #{name}")
    public List<User> getUserName(@Param("name") String name);
    //按照ID查找
    @Select("SELECT * FROM `user` WHERE id = #{id}")
    public User getUserById(@Param("id") Integer id);
    //按照id查找名字
    @Select("SELECT name from `user` WHERE id = #{id}")
    public String getUserNameById(@Param("id") Integer id);
    //插入数据
    @Select("INSERT INTO `user` (NAME, age) VALUES (#{name}, #{age})")
    public int insertUser(@Param("name") String name,@Param("age") Integer age);
    //修改数据
    @Select("UPDATE USER SET `name` = #{name}, age = #{age} WHERE id = #{id}")
    public int updateUserById(@Param("name") String name,@Param("age") Integer age,@Param("id") Integer id);
    //按照ID删除
    @Select("DELETE FROM `user` WHERE id = #{id}")
    public int deleteUserById(@Param("id") Integer id);
    //排序
    @Select("SELECT * FROM `user` group by age ASC")
    public List<User> getAllUser();

}



